//
//  MyselfViewController.m
//  UI_HLJ_Frame
//
//  Created by  毕宏伟 on 15/6/29.
//  Copyright (c) 2015年 毕宏伟. All rights reserved.
//

#import "MyselfViewController.h"
#import "MyTableViewCell.h"

#import "BianJiViewController.h"
#import "ShangPinViewController.h"
#import "JiuDianViewController.h"
#import "ShangJiaViewController.h"
#import "SheZhiViewController.h"



#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface MyselfViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *Myarr;
@property(nonatomic, retain)UIView *headerView;
@property(nonatomic, retain)UILabel *labelUp;
@property(nonatomic, retain)UILabel *labelDown;
@property(nonatomic, retain)UIButton *buttonTX;
@property(nonatomic, retain)UIButton *buttonXY;




@end

@implementation MyselfViewController

- (void)dealloc
{
    [_tableView release];
    [_Myarr release];
    [_headerView release];
    [_labelDown release];
    [_labelUp release];
    [_buttonTX release];
    [_buttonXY release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.Myarr = [NSMutableArray arrayWithObjects:@"收藏的商品",  @"关注的商家", @"设置", nil];
    }

    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"I set up";
    
    // 建立tableview
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 10) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50;
    [_tableView release];
    
    // 建立headerview
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT * 2 / 5)];
    self.tableView.tableHeaderView = self.headerView;
    self.headerView.backgroundColor = [UIColor colorWithRed:0.678 green:0.399 blue:0.621 alpha:1.000];
    [self.headerView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"My背景图片"]]];
    [_headerView release];
    
 /*
    // 下面的label
    self.labelDown = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 50, HEIGHT * 2 / 5 / 2 + 60, 110, 20)];
//    self.labelDown.backgroundColor = [UIColor orangeColor];
    [self.headerView addSubview:self.labelDown];
    self.labelDown.text = @"点击头像登陆";
    [self.labelDown release];
  */  
    // 头像button
    self.buttonTX = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonTX.frame = CGRectMake(WIDTH / 2 - 50, HEIGHT * 2 / 5 / 2 - 50, 100, 100);
    [self.headerView addSubview:self.buttonTX];
    self.buttonTX.layer.borderWidth = 1;
    self.buttonTX.layer.cornerRadius = 50;
//    self.buttonTX.backgroundColor = [UIColor orangeColor];
    [self.buttonTX setImage:[UIImage imageNamed:@"MyTX"] forState:UIControlStateNormal];
    
//    [self.buttonTX addTarget:self action:@selector(BJclick:) forControlEvents:UIControlEventTouchUpInside];
    
    
/*
#pragma mark 右上角按键
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStyleDone target:self action:@selector(click:)];
*/
    
}
/*
#pragma mark 实现右上角的点击方法
- (void)click:(UIButton *)button{
    
    UIAlertView *zhuxiao = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否注销" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    [zhuxiao show];
    [zhuxiao release];
}
*/

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.Myarr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *reuse = @"reuse";
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse]autorelease];
    }
    cell.label.text = self.Myarr[indexPath.row];
    
    [cell.ImageView setImage:[UIImage imageNamed:self.Myarr[indexPath.row]]];

    cell.textLabel.font = [UIFont systemFontOfSize:25];
    
    return cell;
}

// 跳转到编辑页面
//- (void)BJclick:(UIButton *)button{
//    
//    BianJiViewController *bianji = [[BianJiViewController alloc] init];
//    [self.navigationController pushViewController:bianji animated:YES];
//}


#pragma mark 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        ShangPinViewController *shangpin = [[ShangPinViewController alloc] init];
        [self.navigationController pushViewController:shangpin animated:YES];
        
    }
//    else if (indexPath.row == 1){
//        JiuDianViewController *jiudian = [[JiuDianViewController alloc] init];
//        [self.navigationController pushViewController:jiudian animated:YES];
//    
//    }
    else if (indexPath.row == 1){
        ShangJiaViewController *shangjia = [[ShangJiaViewController alloc] init];
        [self.navigationController pushViewController:shangjia animated:YES];
        
    } else if (indexPath.row == 2){
        SheZhiViewController *shezhi = [[SheZhiViewController alloc] init];
        [self.navigationController pushViewController:shezhi animated:YES];
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
